﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace SciZip
{
    static class Program
    {
        private static string[] Args = null;
        private static string Password = null;

        private static void AnalyseArgs(string[] args)
        {
            List<string> list = new List<string>();
            if ((args != null) && (args.Length > 0))
            {
                foreach (string str in args)
                {
                    string item = str.Trim();
                    if (item.StartsWith("PASS:"))
                    {
                        Password = item.Substring("PASS:".Length);
                    }
                    else
                    {
                        list.Add(item);
                    }
                }
            }
            Args = list.ToArray();
        }

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);

            DllTool.LoadResourceDll();                // 载入依赖dll
            _Main(args);
        }

        private static void _Main(string[] args)
        {
            //Application.Run(new Form1());

            if ((args != null) && (args.Length > 0))
            {
                AnalyseArgs(args);
                process(Args, Password);
            }
            else
            {
                MessageBox.Show("拖动待压缩或解压的文件至此应用，即可进行压缩或解压。\r\n通过cmd调用时，传参数PASS:***可指定密码！");
            }
        }

        private static void process(string[] args, string password)
        {
            if ((args != null) && (args.Length > 0))
            {
                ZipTool.Process(Args, Password);
            }
        }
    }
}
